#!/usr/bin/env python3
# 用于生成 index.json 配置

import json
import requests


def main():
    url = 'https://geo.datav.aliyun.com/areas_v2/bound/infos.json'
    resp = requests.get(url)
    if resp.status_code != 200:
        print('获取地理索引数据失败')
        exit(1)
    config = resp.json()
    new_config = []
    for k, v in config.items():
        if v['childrenNum'] > 0:
            new_config.append((int(k), v['name']))
    with open('index.json', 'w') as fp:
        fp.write(json.dumps(new_config, ensure_ascii=False))


if __name__ == '__main__':
    main()
